package com.pb.infra.dynamicSetting.dynamTableColumnCfg.controller;

import com.pb.infra.dynamicSetting.dynamTableColumnCfg.entity.MaFrDynamTableColumnCfg;
import com.pb.infra.dynamicSetting.dynamTableColumnCfg.service.MaFrTableColumnService;
import com.pb.infra.oth.entity.common.Result;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * 动态表格 列管理(MaFrTableColumn)表控制层
 *
 * @author makejava
 * @since 2022-03-09 15:12:05
 */
@RestController
@RequestMapping("/maFrTableColumn")
public class MaFrTableColumnController{
    /**
     * 服务对象
     */
    @Resource
    private MaFrTableColumnService maFrTableColumnService;

    /**
     * 分页查询所有数据
     *
     * @param maFrDynamTableColumnCfg 查询实体
     * @return 所有数据
     */
    @PostMapping("/list")
    public Result selectAll(@RequestBody MaFrDynamTableColumnCfg maFrDynamTableColumnCfg) {
        return this.maFrTableColumnService.queryList(maFrDynamTableColumnCfg);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/{id}")
    public Result selectOne(@PathVariable String id) {
        return this.maFrTableColumnService.queryById(id);
    }

    /**
     * 新增数据
     *
     * @param maFrDynamTableColumnCfg 实体对象
     * @return 新增结果
     */
    @PostMapping("/add")
    public Result insert(@RequestBody MaFrDynamTableColumnCfg maFrDynamTableColumnCfg) {
        return this.maFrTableColumnService.insert(maFrDynamTableColumnCfg);
    }

    /**
     * 修改数据
     *
     * @param maFrDynamTableColumnCfg 实体对象
     * @return 修改结果
     */
    @PostMapping("/upd")
    public Result update(@RequestBody MaFrDynamTableColumnCfg maFrDynamTableColumnCfg) {
        return this.maFrTableColumnService.update(maFrDynamTableColumnCfg);
    }

    /**
     * 删除数据
     *
     * @return 删除结果
     */
    @PostMapping("/del")
    public Result delete(@RequestBody MaFrDynamTableColumnCfg maFrDynamTableColumnCfg) {
        return this.maFrTableColumnService.delete(maFrDynamTableColumnCfg);
    }

    /**
     * 删除数据
     *
     * @return 删除结果
     */
    @PostMapping("/syncTableCol")
    public Result syncTableCol(@RequestBody MaFrDynamTableColumnCfg maFrDynamTableColumnCfg) {
        return this.maFrTableColumnService.syncTableCol(maFrDynamTableColumnCfg);
    }


    /**
     * 导入数据
     *
     * @return 导入结果
     */
    @PostMapping("/import")
    public Result colImport(@RequestParam Map<String, Object> paramMap, MultipartHttpServletRequest multipartHttpServletRequest) {
        return this.maFrTableColumnService.colImport(paramMap,multipartHttpServletRequest);
    }


    /**
     * 导出
     *
     * @return 导出结果
     */
    @PostMapping("/export")
    public void colExport(@RequestBody MaFrDynamTableColumnCfg maFrDynamTableColumnCfg, HttpServletResponse response) {
        this.maFrTableColumnService.colExport(maFrDynamTableColumnCfg,response);
    }
}

